/**
 * Created by DELL on 2017/6/23.
 */
(function() {
    'use strict';
    var checkedObject = {};
    common.buildNormalEnumSelect(".exchangeStatus",enumObject.enumJsonData['exchangeStatus']);
    /**
     * 中介联系人 列表初始化设置
     * @type {Object}
     */
    var settings = {
        "sAjaxSource": window.globalHost + common.agentGetMoneyByCreditListPath,
        "aoColumns": [{
            "mDataProp": function(obj) {
                return (obj.agentName===""?"无信息":obj.agentName)+" / "+(obj.mobile===""?"无信息":obj.mobile);
            },
            "sTitle": "经纪人",
            "sDefaultContent": ""
        },{
            "mDataProp": "createTime",
            "sTitle": "申请提现时间",
            "sDefaultContent": ""
        },{
            "mDataProp": function (obj) {
                return !obj.money?"无信息":obj.money;
            },
            "sTitle": "提现金额",
            "sDefaultContent": ""
        },{
            "mDataProp": function(obj) {
                // return obj. creditDepleted===""?"无信息":obj.creditDepleted;
                return !obj. exchangePoint?"无信息":obj.exchangePoint;
            },
            "sTitle": "消耗积分",
            "sDefaultContent": ""
        },{
            "mDataProp": "alipayAccount",
            "sTitle": "支付宝账号",
            "sDefaultContent": ""
        },{
            "mDataProp": "alipayName",
            "sTitle": "支付宝姓名",
            "sDefaultContent": ""
        },{
            "mDataProp": function (obj) {
                return enumObject.enumJsonData["exchangeStatus"][obj.exchangeStatus];
            },
            "sTitle": "处理状态",
            "sDefaultContent": ""
        },{
            "mDataProp":function (obj) {
                return obj.updateTime==obj.createTime?"":obj.updateTime;

            },
            "sTitle": "打款时间",
            "sDefaultContent": ""
        },{
            "mDataProp": function (obj) {
                var btn='';
                if(obj.exchangeStatus=="0"){
                    btn='<a href="javascript:;" class="btn btn-success sure" data-id="'+obj.id+'">确认打款</a>'
                }
                return btn;
            },
            "sTitle": "操作",
            "sDefaultContent": "",
            "sClass": "text-center"
        }],
        "fnServerParams": function(aoData) {
            return common.getSearchData("form.data-list-search",aoData);
        }
    };
    var options = $.extend(true, {}, _dataTableSettings, settings);
    /**
     * 实例化 中介联系人 列表插件
     * @type {[type]}
     */
    var $currentDataTable=$("#data-list");
    var oTable = $currentDataTable.dataTable(options);
    searchList.getDataList(oTable);
    searchList.resetSearch(oTable);
    $currentDataTable.off("click",".sure").on("click",".sure",function (e) {
        var $this=$(this);
        var sendData={id:$this.attr("data-id"),exchangeStatus:"1"};
        common.confirm({msg:"是否确认打款?"}).then(function() {
            $.post(window.globalHost + common.agentGetMoneyByCreditUpdatePath, sendData).success(function (data) {
                if (typeof data == "string") {
                    data = JSON.parse(data);
                }
                layer.alert(data.res.msg);
                $currentDataTable.fnClearTable();
            });
        });
    });
}).call(this);